<?php
/**
* @package		auto_occasion
* @subpackage	commun
* @version		1
*/
require_once(LIB_PATH.'phpMailer/class.phpmailer.php');


/**
* Fonctions utilitaires pour l'envoi des mail
* @subpackage commun
*/
class toolsMail {
    /**
     * Envoi de mail
     * @param $datas 
     * attrubutes : email, Username, FromName, Subject, message
     */
     public function sendMail($datas) {

        $mail = new PHPmailer();
        $mail->IsSMTP();
        $mail->IsHtml(true);
        if (is_array($datas->email) && sizeof($datas->email)) {
            foreach($datas->email as $item)
            {
                $mail->AddAddress($item);
            }

        } else {
            $mail->AddAddress($datas->email);
        }
        $mail->Host         = $GLOBALS['gJConfig']->mailer['smtpHost'];
        $mail->Port         = $GLOBALS['gJConfig']->mailer['smtpPort'];
        $mail->Username     = $datas->Username;
        $mail->From         = $GLOBALS['gJConfig']->mailer['webmasterEmail'];
        $mail->FromName     = $datas->FromName;
        $mail->Subject      = $datas->Subject;
    
        $mail->Body         = $datas->message ;
        
        if (!$mail->Send()){
          echo $mail->ErrorInfo;
          die('Sending mail - Error');
        }
        
        $mail->SmtpClose();
        $mail->ClearAddresses();
        unset($mail);
        
     }
}
	